package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.core.genertor.UniqueIdGenerator;
import com.csun.cmny.core.utils.RequestUtil;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.security.core.validate.code.sms.SmsCodeSender;
import com.csun.cmny.util.PubUtils;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-09-25 11:58
 * @Description: the class uac sms controller
 */
@RestController
@RequestMapping(value = "/api", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class UacSmsController {

    @Autowired
    private SmsCodeSender smsCodeSender;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    /**
     * 发送短信
     */
    @PostMapping(value = "/sendSms")
    public Wrapper sendSms(HttpServletRequest request, @RequestParam String mobile) {

        String resetPwdKey = PubUtils.uuid() + UniqueIdGenerator.generateId();
        String ipAddr = RequestUtil.getRemoteAddr(request);

        smsCodeSender.send(mobile, "123456", ipAddr, null);

        //return WrapMapper.ok(resetPwdKey);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), resetPwdKey);
    }

}
